<?php
echo "abc 2";
fprint($_POST);
if(isset($_POST["connect"]))
{
	
     require_once('libraries/facebook.php' );
      $facebook = new Facebook(array(
        'appId' =>"654197201258828",
        'secret' =>"1fac7290652c1dc4b44f64654f877f44",
    ));
    $fbuser = $facebook->getUser();
    if ($fbuser) {
		
        try {
            // Proceed knowing you have a logged in user who's authenticated.
            $me = $facebook->api('/me'); //user
            $uid = $facebook->getUser();
		 
			
        }
        catch (FacebookApiException $e)
        {
                 $fbuser = null;
        }
    }

    // redirect user to facebook login page if empty data or fresh login requires
    if (!$fbuser){
        $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>"http://localhost/gameavatar.net/index.php?module=user&act=login", false));
        header('Location: '.$loginUrl);
    }
  	//user details
      $_SESSION['user']=$me;
	  $_SESSION['user']['fbid']=$uid;
	 $fullname=$me['name'];
	  $email=$me['email']; 
	   	$db=new db;
		$db->connect();
		$sql="SELECT id FROM user_face WHERE fbid='$uid'";
		 $db->query($sql);
		
   

    if($db->num_rows()==0)
    {
		$sql="INSERT INTO user_face(fbid, fullname, email) VALUES($uid, '$fullname','$email')";
	        $db->query($sql);
	
	 }
}
exit();
?>